#include "EpilReturnStatementInterpreter.h"
#include "EpilInterpreterException.h"
#include "EpilInterpreter.h"
#include "EpilExpressionListInterpreter.h"
#include <algorithm>

using namespace std;


EpilReturnStatementInterpreter::EpilReturnStatementInterpreter( EpilInterpreter * interpreter )
: EpilInterpreterBase( interpreter )
, m_exitReason( ECER_Normal )
, m_exitLocation( EpilLexLocation::InvalidLocation )
{
}


void EpilReturnStatementInterpreter::Run( const EpilReturnStatementCode * code )
{
	EpilExpressionListInterpreter eli( this->GetInterpreter() );
	eli.Run( code->GetExpressions() );
	
	EpilObjectList objs = eli.GetObjects();
	EpilObjectVector rets;

	copy( objs.begin(), objs.end(), back_inserter( rets ) );

	this->GetInterpreter()->SetReturns( rets );

	m_exitReason = ECER_Return;
	m_exitLocation = code->GetLocation();
}